//
//  LZMyCenterUserInfoTableViewCell.m
//  laziz_Merchant
//
//  Created by ZhaoDongBo on 2016/12/17.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZMyCenterUserInfoTableViewCell.h"

#import "Masonry.h"

@implementation LZMyCenterUserInfoTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor = UIColorFromRGB(0xffffff, 1);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self configView];
        [self addAutoLayoutToCell];
    }
    return self;
}

- (void)clickMarkImageAction
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickMarkImageView)]) {
        [self.delegate clickMarkImageView];
    }
}

- (void)configView {
    [self.contentView addSubview:self.bgImageView];
    [self.contentView addSubview:self.userBgImageView];
    [self.userBgImageView addSubview:self.userImageView];
    [self.contentView addSubview:self.userNameLabel];
    [self.contentView addSubview:self.editButton];
    [self.editButton addSubview:self.editImage];
    [self.editButton addSubview:self.editLabel];
}

- (void)addAutoLayoutToCell {
    
    WS(weakSelf);
    [self.bgImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(0);
        make.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];

    [self.userBgImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(weakSelf.mas_centerX);
        make.centerY.mas_equalTo(weakSelf.mas_centerY).with.offset(-30);
        make.size.mas_equalTo(CGSizeMake(105, 105));
    }];
    
    [self.userImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(weakSelf.userBgImageView.mas_centerX);
        make.centerY.mas_equalTo(weakSelf.userBgImageView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];

    [self.userNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.userImageView.mas_bottom).with.offset(15);
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
    }];
    
    [self.editButton makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_lessThanOrEqualTo(-10);
        make.bottom.mas_equalTo(-10);
        make.height.mas_equalTo(24);
    }];
    
    [self.editImage makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(5.5);
        make.top.mas_equalTo(6.5);
        make.size.mas_equalTo(CGSizeMake(5.5, 11));
    }];
    
    [self.editLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.editButton.centerY);
        make.leading.mas_equalTo(weakSelf.editImage.mas_trailing).with.offset(5);
        make.trailing.mas_equalTo(-10);
        make.height.mas_equalTo(24);
    }];
}

- (UIImageView *)bgImageView {

    if (_bgImageView == nil) {
        _bgImageView = [[UIImageView alloc] init];
        _bgImageView.image = [UIImage imageNamed:@"lz_userinfo_cellbg"];
    }
    
    return _bgImageView;
}

- (UIImageView *)userBgImageView {

    if (_userBgImageView == nil) {
        _userBgImageView = [[UIImageView alloc] init];
        _userImageView.layer.masksToBounds  = YES;
        _userImageView.layer.cornerRadius   = 52.5;
        _userBgImageView.image = [UIImage imageNamed:@"lz_userinfo_bgimage"];
    }
    
    return _userBgImageView;
}

- (UIImageView *)userImageView {
    
    if (_userImageView == nil) {
        _userImageView = [[UIImageView alloc] init];
        _userImageView.layer.masksToBounds  = YES;
        _userImageView.layer.cornerRadius   = 50;
        _userImageView.image = [UIImage imageNamed:@"lz_userinfo_bg_headerimage"];
    }
    
    return _userImageView;
}

- (UILabel *)userNameLabel {
    if (_userNameLabel == nil) {
        _userNameLabel = [[UILabel alloc] init];
        _userNameLabel.text         = @"The Meat Co";
        _userNameLabel.font         = [UIFont systemFontOfSize:15];
        _userNameLabel.textColor    = UIColorFromRGB(0xffffff, 1);
        _userNameLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    return _userNameLabel;
}

- (UIButton *)editButton {
    if (_editButton == nil) {
        _editButton = [[UIButton alloc] init];
        _editButton.backgroundColor     = UIColorFromRGB(0x000000, 1);
        _editButton.layer.masksToBounds = YES;
        _editButton.layer.cornerRadius  = 12;
    }
    
    return _editButton;
}

- (UIImageView *)editImage {
    if (_editImage == nil) {
        _editImage = [[UIImageView alloc] init];
        _editImage.image = [UIImage imageNamed:@"lz_userinfo_editimage"];
    }
    
    return _editImage;
}

- (UILabel *)editLabel {
    if (_editLabel == nil) {
        _editLabel = [[UILabel alloc] init];
        _editLabel.text         = LZLocalizedString(@"personal_info", nil);
        _editLabel.font         = [UIFont systemFontOfSize:12];
        _editLabel.textColor    = UIColorFromRGB(0xffffff, 1);
        _editLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickMarkImageAction)];
        [_editLabel addGestureRecognizer:tap];

    }
    
    return _editLabel;
}


@end
